<?php


namespace app\index\controller;


use app\common\model\Users;
use app\index\validate\EditValidate;
use think\Controller;

class User extends BaseController
{
    public function userInfo(){
        $user =  session('vol_user');
        $userInfo = model('users')->find($user['id']);
        $this->assign(compact('userInfo'));
        return view();
    }
    public function userInfoEdit(){
        $user =  session('vol_user');
        $userInfo = model('users')->find($user['id']);
        if(request()->isPost()){
            $data = input('post.');
            $data['vol_reg_year'] = $data['vol_reg_year'] ? $data['vol_reg_year'] : $userInfo['vol_reg_year'];
            $data['vol_reg_month'] = $data['vol_reg_month'] ? $data['vol_reg_month'] : $userInfo['vol_reg_month'];
            $data['vol_reg_day'] = $data['vol_reg_day'] ? $data['vol_reg_day'] : $userInfo['vol_reg_day'];
            $result = $this->validate($data,EditValidate::class);
            if(true !== $result){
                $this->error($result);
            }
            $res = model('users')->save($data,['id'=>$user['id']]);
            if($res){
                $this->success('修改成功','index/user/userInfo');
            }else{
                $this->error("未作任何修改");
            }

        }

        $this->assign(compact('userInfo'));
        return view();
    }
    public function wait(){
        $id = session('vol_user.id');
        $project = model('apply')::with('getProject')->where(['user_id'=>$id,'status'=>1])->select();
        $this->assign(compact('project'));
        return view();
    }
    public function waitDetail(){
        $project = model('project')->find(input('id'));
        $this->assign(compact('project'));
        return view();
    }
    public function allow(){
        $id = session('vol_user.id');
        $project = model('apply')::with('getProject')->where(['user_id'=>$id,'status'=>2])->select();
        $this->assign(compact('project'));
        return view();
    }
    public function allowDetail(){
        if(request()->isPost()){
            $text = input('post.text');
            $vol_project = model('apply')->where('project_id',input('post.id'))->where('user_id',session('vol_user.id'))->find();
            $vol_project->text = $text;
            $vol_project->status = 4;
            $vol_project->save();
            $this->success('提交取消成功','index/user/allow');
        }
        $project = model('project')->find(input('id'));
        $this->assign(compact('project'));
        return view();
    }
    public function my_index(){
        return view();
    }
    public function my_project(){
        $id = session('vol_user.id');
        $project = model('apply')::with('getProject')->where(['user_id'=>$id])->select();
        $this->assign(compact('project'));
        return view();
    }
    public function my_project_detail(){
        if(request()->isPost()){
            $text = input('post.text');
            $vol_project = model('apply')->where('project_id',input('post.id'))->where('user_id',session('vol_user.id'))->find();
            $vol_project->text = $text;
            $vol_project->status = 4;
            $vol_project->save();
            $this->success('提交取消成功',$_SERVER['HTTP_REFERER']);
        }
        $project = model('apply')::with('getProject')->find(input('id'));
        $this->assign(compact('project'));
        return view();
    }
    //前台用户个人服务时长
    public function serviceTime(){
        $users = model('users')->find(session('vol_user.id'));
        $this->assign(compact('users'));
        return view();
    }
    //我的积分
    public function integral(){
        $users = model('users')->find(session('vol_user.id'));
        $this->assign(compact('users'));
        return view();
    }
    public function showCard(){
        $users = model('users')->find(session('vol_user.id'));
        $this->assign(compact('users'));
        return view();
    }
}
